import {
  ContractStatus,
  UpdateAuthorStatusReq,
} from '@/api/premium/content/model/authorModel'
import { AuthorApi, updateAuthorStatus } from '@/api/premium/content/author'
import { useStore } from '@/store'
import { message } from 'ant-design-vue'
import { computed } from 'vue'

const useAuditAuthor = (searchApi: () => Promise<void>) => {
  const store = useStore()

  const updateAuthorStatusLoading = computed(() =>
    store.getters['global/isOpLoading'](AuthorApi.UPDATE_AUTHOR_STATUS)
  )

  const unContract = async (id: string) => {
    const reqData: UpdateAuthorStatusReq = {
      id,
      contractStatus: ContractStatus.UNCONTRACT,
    }
    await updateAuthorStatus(reqData)
    message.success('解约成功！')
    await searchApi()
  }
  const contract = async (id: string) => {
    const reqData: UpdateAuthorStatusReq = {
      id,
      contractStatus: ContractStatus.NORMAL,
    }
    await updateAuthorStatus(reqData)
    message.success('再签成功！')
    await searchApi()
  }

  return {
    updateAuthorStatusLoading,
    unContract,
    contract,
  }
}

export default useAuditAuthor
